home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Mod or if?
- Date: 11 Feb 1996 11:47:24 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4fkl0c$nrt@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe10.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 09, 1996 18:25:58 in article <Mod or if?>, 'weikel@rohan.sdsu.edu
- (weikel)' wrote:
-
-
- >Which is better?
- >
- >x = (x mod 7);
- >
- What's mod? Maybe you mean x = x % 7; or its abbreviation
- x %= 7; (Not quite the same as modulus since in C/C++ we
- have only the remainder operator)
-
- >or
- >
- >if (x == 7) x = 0;
- >
- >in terms of performance? I know that the mod function is slow
- >,but the if method seems brute-forceish.
- >
- The if method is much faster -- mostly because it doesn't
- give the same result.
-
- BTW, worrying about the performance of built-in operators is
- usually a waste of time.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-